package com.qyy.remotemonitor.common.ui;

import android.os.Bundle;
import android.util.Log;

import com.blankj.utilcode.util.LogUtils;
import com.qyy.remotemonitor.MyApplication;
import com.qyy.remotemonitor.common.di.ActivityCommonComponent;
import com.qyy.remotemonitor.common.di.DaggerActivityCommonComponent;
import com.qyy.remotemonitor.common.di.interfaces.DiActivitySupport;
import com.wang.android.library.di.EasyBasePresenter;
import com.wang.android.library.di.modules.ActivityModule;
import com.wang.android.library.network.eventbus.WHttpEventBean;
import com.wang.android.library.ui.FBaseDaggerActivity;

import javax.inject.Inject;


public abstract class BaseActivity<P extends EasyBasePresenter> extends FBaseDaggerActivity
        implements DiActivitySupport
{
    @Inject
    protected P presenter;


    @Override
        public void onCreate(Bundle savedInstanceState)
    {
        long time  = System.currentTimeMillis();
        initInject();
        RequestedOrientation = false;
        if(presenter != null){
            presenter.attachView(this);
            presenter.setContext(this);
        }
        super.onCreate(savedInstanceState);
        Log.e("qqqqqqqqqq","cost time is " + (System.currentTimeMillis()- time));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(presenter != null){
            presenter.detachView();
        }
    }




    @Override
    public void onEvent(WHttpEventBean wNetEventBean) {
    }

    @Override
    public abstract void initInject();

    @Override protected void onResume()
    {
        super.onResume();
        LogUtils.d("=================this is " + this.getClass().getSimpleName() + "=================");
    }


    @Override
    public ActivityCommonComponent getActivityComponent() {
        return DaggerActivityCommonComponent.builder()
                .appCommonComponent(((MyApplication) getApplication()).getAppCommonComponent())
                .activityModule(getActivityModule())
                .build();
    }

    @Override
    public ActivityModule getActivityModule() {
        return new ActivityModule(this);
    }


    public P getPresenter()
    {
        return presenter;
    }

}
